home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / util / cli / WBScreen.lha / src / WBScreen.c < prev   
Encoding:
C/C++ Source or Header  |  1998-05-01  |  4.0 KB  |  137 lines

  1. /*
  2. **  WBScreen.c
  3. **
  4. **  Open or close the Workbench. Can also make another screen the default
  5. **  public screen.
  6. */
  7.  
  8.  
  9. #include <exec/types.h>
  10. #include <intuition/intuition.h>
  11. #include <proto/dos.h>
  12. #include <proto/exec.h>
  13. #include <proto/graphics.h>
  14. #include <proto/intuition.h>
  15. #include <string.h>
  16.  
  17.  
  18.  
  19. UBYTE *Version = { "$VER: WBScreen 2.11 (30.04.98)" };
  20.  
  21.  
  22.  
  23. int main( int argc, char *argv[] )
  24. {
  25.   BOOL ret = 5;
  26.   char *ptr, **ttypes;
  27.   struct List *psList;
  28.   struct PubScreenNode *psNode;
  29.   ULONG secs, ticks = GfxBase->DisplayFlags & PAL ? 50 : 60;
  30.   
  31.     
  32.   if ( IntuitionBase = ( struct IntuitionBase * )
  33.                                    OpenLibrary( "intuition.library", 37L ))
  34.     {
  35.       if ( ttypes = ArgArrayInit( argc, argv ) )
  36.         {
  37.           ptr = ArgString( ttypes, "CLOSE", 0 );
  38.           
  39.           if ( ptr )
  40.             CloseWorkBench();
  41.           
  42.           
  43.           ptr = ArgString( ttypes, "OPEN", 0 );
  44.           
  45.           if ( ptr )
  46.             OpenWorkBench();
  47.           
  48.           
  49.           secs = ticks * ( ArgInt( ttypes, "DELAY", 0 ));
  50.           
  51.           if ( secs )
  52.             Delay( secs );      // Wait before trying to find the screen. 
  53.             
  54.           
  55.           ptr = ArgString( ttypes, "DEFAULT", 0 );
  56.           
  57.           if ( ptr )                //  If a pub screen name is specified 
  58.             {                       //  we'll make that one the default.  
  59.               struct Screen *scr;   //  If AUTO is specified, we'll make  
  60.                                     //  the frontmost screen the default. 
  61.               
  62.               if ( stricmp( ptr, "AUTO" ) == NULL )
  63.                 {
  64.                   ULONG lock;
  65.                   
  66.                   lock = LockIBase( NULL );   //  Get a ptr to first scr. 
  67.                   
  68.                     scr = IntuitionBase->FirstScreen;
  69.                     
  70.                   UnlockIBase( lock );  
  71.                     
  72.                   
  73.                   psList = LockPubScreenList();
  74.                   
  75.                   psNode = ( struct PubScreenNode * ) psList->lh_Head;
  76.                   
  77.                   while ( psNode )
  78.                     {
  79.                       if ( scr == psNode->psn_Screen )
  80.                         {
  81.                           ptr = psNode->psn_Node.ln_Name;
  82.                           
  83.                           break;            //  Find the pub screen name  
  84.                         }                   //  of this frontmost screen. 
  85.                       
  86.                       psNode = ( struct PubScreenNode * )
  87.                                                   psNode->psn_Node.ln_Succ;
  88.                     }
  89.                   
  90.                   UnlockPubScreenList();
  91.                 }
  92.               
  93.               
  94.               if ( scr = LockPubScreen( ptr ))
  95.                 {
  96.                   SetDefaultPubScreen( ptr );
  97.                   
  98.                   SetPubScreenModes( POPPUBSCREEN | SHANGHAI );
  99.                   
  100.                   UnlockPubScreen( NULL, scr );
  101.                 }
  102.             }
  103.           
  104.           ArgArrayDone();
  105.         
  106.         
  107.           if (! secs )             //  Wait until Workbench is removed    
  108.             Delay( ticks / 6 );    //  from or added to PubScreenList.    
  109.           
  110.           psList = LockPubScreenList();
  111.           
  112.           psNode = ( struct PubScreenNode * ) psList->lh_Head;
  113.           
  114.           while ( psNode )
  115.             {
  116.               if ( strcmp( psNode->psn_Node.ln_Name,
  117.                                                     "Workbench" ) == NULL )
  118.                 {
  119.                   ret = 10;     //  Because of a bug in CloseWorkbench(), 
  120.                                 //  which always returns 0, we check here 
  121.                   break;        //  if the Workbench is opened or not.    
  122.                 }
  123.               
  124.               psNode = ( struct PubScreenNode * ) psNode->psn_Node.ln_Succ;
  125.             }
  126.           
  127.           UnlockPubScreenList();
  128.         }
  129.       
  130.       
  131.       CloseLibrary( ( struct Library * ) IntuitionBase );
  132.     }
  133.   
  134.   
  135.   return ret;
  136. }
  137.